﻿Imports System
Imports System.Data
Imports System.Windows.Forms
Imports MySql.Data.MySqlClient
Public Class mainview
    Dim conn As MySqlConnection
    Dim data As DataTable
    Dim da As MySqlDataAdapter
    Dim cb As MySqlCommandBuilder

    Private Sub mainview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim connstr As String
        Dim cmd As MySqlCommand
        Dim comm As String
        Dim server_state As Boolean = 1

        Dim userid As String
        Dim temp() As String
        
        'Display the splash screen
        'frmSplash(SplashScreen = New frmSplash())

        SplashScreen.Show()

        'show the splash form and update text as events occur
        'SplashScreen.lblStatus.Text = "Helpful information here"
        'SplashScreen.lblStatus.Refresh()
        'call the method to perform the action
        'Repeat the update of the text and calling methods until program is ready to run.
        'Close the splash screen

        connstr = My.Settings.MysqlDB
        If (Len(connstr) = 0) Then
            MessageBox.Show("数据库服务器未设置", "错误")
            server_state = 0
        End If

        If (server_state) Then
            temp = Split(My.Settings.MysqlDB, ";")
            userid = temp(1)
            temp = Split(userid, "=")
            userid = temp(1)

            connstr = My.Settings.MysqlDB
            conn = New MySqlConnection(connstr)
            data = New DataTable
            comm = String.Format("SELECT * FROM user WHERE username='{0}'", userid.ToString)
            da = New MySqlDataAdapter(comm, conn)
            cb = New MySqlCommandBuilder(da)
            da.Fill(data)
            DataGridView1.DataSource = data

            Me.DataGridView1.CurrentCell = Me.DataGridView1(4, 0)
            pub.YGCX = Me.DataGridView1.CurrentCell.Value.ToString
            Me.DataGridView1.CurrentCell = Me.DataGridView1(1 + Me.DataGridView1.CurrentCellAddress.X, 0)
            pub.YGGL = Me.DataGridView1.CurrentCell.Value.ToString
            Me.DataGridView1.CurrentCell = Me.DataGridView1(1 + Me.DataGridView1.CurrentCellAddress.X, 0)
            pub.DDGL = Me.DataGridView1.CurrentCell.Value.ToString
            Me.DataGridView1.CurrentCell = Me.DataGridView1(1 + Me.DataGridView1.CurrentCellAddress.X, 0)
            pub.CJGL = Me.DataGridView1.CurrentCell.Value.ToString
            Me.DataGridView1.CurrentCell = Me.DataGridView1(1 + Me.DataGridView1.CurrentCellAddress.X, 0)
            pub.SCGL = Me.DataGridView1.CurrentCell.Value.ToString
            Me.DataGridView1.CurrentCell = Me.DataGridView1(1 + Me.DataGridView1.CurrentCellAddress.X, 0)
            pub.SCCX = Me.DataGridView1.CurrentCell.Value.ToString
            Me.DataGridView1.CurrentCell = Me.DataGridView1(1 + Me.DataGridView1.CurrentCellAddress.X, 0)
            pub.GJGL = Me.DataGridView1.CurrentCell.Value.ToString
            Me.DataGridView1.CurrentCell = Me.DataGridView1(1 + Me.DataGridView1.CurrentCellAddress.X, 0)
            pub.GZJS = Me.DataGridView1.CurrentCell.Value.ToString

            Me.Button1.Enabled = pub.YGCX
            yuangong_detail.Button1.Enabled = pub.YGGL
            yuangong_detail.Button2.Enabled = pub.YGGL
            yuangong_detail.Button3.Enabled = pub.YGGL
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        SplashScreen.Close()
        Me.Opacity = 1
    End Sub

    '添加员工
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'add.Show()
        Me.Enabled = False
    End Sub

    '关闭
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()
    End Sub

    '员工查询
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        yuangongchaxun.Show()
        Me.Enabled = False
    End Sub

    '系统设置
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        sys_config.Show()
        Me.Enabled = False
    End Sub

End Class